#!/usr/bin/python -OO
# -*- coding: utf8 -*-

import os
import sys

if __name__ == "__main__":
    currentdir = os.path.dirname( os.path.abspath( sys.argv[0] ) )
    basedir = os.path.abspath( os.path.join( currentdir, ".." ) )
    pythondir = basedir
    sys.path.insert( 0, pythondir )

def launch():

    from argparse import ArgumentParser

    parser = ArgumentParser(description='Run image archive extraction tool.')
    parser.add_argument('--archive', dest='archive', action='store', type=str,
        help='Archive file name')
    parser.add_argument('--mime', dest='mime', action='store', type=str,
        help='Archive file MIME')
    parser.add_argument('--into-dir', dest='into_dir', action='store', type=str,
        help='Extract into directory')

    args = parser.parse_args()

    from archive import Archive

    arch = Archive(args.archive, args.mime)
    if arch.extract_files(args.into_dir):
        return 0
    return 1

if __name__ == "__main__":
    sys.exit(launch())
